<template>
	<view>
		<view>
			<u-tabs-swiper ref="uTabs" :list="list" name="cate_name" :current="current" @change="tabsChange" :is-scroll="false"></u-tabs-swiper>
		</view>
		<swiper class="course-big" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
			<swiper-item class="swiper-item" v-for="(item, index) in tabs" :key="index">
				<scroll-view scroll-y style="height: 900rpx;width: 100%;">
					<view  v-if="index==0">
						<view class="big-watch" v-for="(item,index) in recordList" @click="goDetail(item.courseId)" :key='item.courseCover'>
							<view class="time">
								{{item.lastStudyTime}}
									<!-- <view>22/01/22</view>
									<view>08:57:08</view> -->
							</view>
							<image class="watch-img" :src="item.bannerFileUrl"></image>
							<view class="class-title">
								{{item.courseTitle}}
							</view>
						</view>
					</view>
					<view v-if="index==1">
						<view class="boutique-content">
							<view class="small-content" v-for="(item,index) in collectList" @click="goDetail(item.courseId)" :key='item.courseCover'>
								<image :src="item.bannerFileUrl" class="class-img" mode=""></image>
								<view class="bottom-title">
									{{item.courseTitle}}
								</view>
								<view class="bottom-tip">
									<view class="free-word">
										免费
									</view>
									<view class="small-live">
										<image src="../../static/images/live.png" mode="widthFix"></image>
										{{item.participationsCount}}
									</view>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import {getGet} from "../../api/index.js"
	export default {
		data() {
			return {
				collectList:"",//我的收藏
				recordList:"",//观看记录
				list: [{
					cate_name: '观看记录'
				}, {
					cate_name: '我的收藏'
				}],
				current: 0, // tabs组件的current值，表示当前活动的tab选项
				swiperCurrent: 0, // swiper组件的current值，表示当前那个swiper-item是活动的
				tabs:[1,2]
			}
		},
		methods: {
			change(index) {
				this.current = index;
			},
			// tabs通知swiper切换
			tabsChange(index) {
				this.swiperCurrent = index;
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				let dx = e.detail.dx;
				this.$refs.uTabs.setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.uTabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			},
			goDetail(data){
				uni.navigateTo({
					url:`/pages/detail/detail?id=${data}`
				})
			}
		},
		onShow(){
			// console.log(111)
			getGet("/weChat/applet/course/init/myCourse").then(res=>{
				// console.log(res.data.recordList)
				this.collectList=res.data.collectList
				this.recordList=res.data.recordList
			})
		},
	}
</script>

<style lang="less" scoped>
.big-watch{
	padding: 30rpx;
	display: flex;
	justify-content: flex-end;
	align-items: center;
	background-color: #f5f5f5;
}
.time{
	width: 200rpx;
}
.watch-img{
	width: 300rpx;
	height: 180rpx;
}
.class-title{
	width: 250rpx;
	margin: 0 0 80rpx 20rpx;
}
.course-big{
	height: 1000rpx;
}
	.small-content{
		display: flex;
	}
	.boutique-content{
		padding: 15rpx;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
	}
	.small-live{
		image{
			width: 20rpx;
			margin-right: 10rpx;
		}
	}
	.class-img{
		width: 340rpx;
		height: 170rpx;
	}
	.bottom-title{
		height: 34px;
	}
	.small-content{
		padding: 10rpx 0;
		width: 340rpx;
		display: flex;
		flex-direction: column;
	}
	.bottom-tip{
		margin-top: 15rpx;
		display: flex;
		justify-content: space-between;
	}
	.free-word{
		color: #00cf8c;
	}
	.top-tips{
		font-size: 30rpx;
		font-weight: bold;
	}
	.top-title{
		padding: 20rpx 0;
		display: flex;
		justify-content: space-between;
	}
</style>
